package com.xhtt.modules.app.controller.reportform;

import com.xhtt.common.utils.Constant;
import com.xhtt.common.utils.R;
import com.xhtt.modules.app.annotation.Login;
import com.xhtt.modules.task.service.TaskCarTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 统计分析-app装车任务
 **/

@RestController
@RequestMapping(value = "app/report/car")
@Api(value = "统计分析-app装车任务", tags = "统计分析-app装车任务")
public class AppCarReportController {
    @Autowired
    private TaskCarTaskService taskCarTaskService;

    @GetMapping(value = "/carForUser")
    @ApiOperation("装车人员统计分析")
    @Login
    public R carForUser(@RequestParam Map<String, Object> params) {
        List<Map<String, Object>> result = taskCarTaskService.carForUser(params);
        return R.ok().put(Constant.DATA, result);
    }

    @GetMapping(value = "/carForStand")
    @ApiOperation("装车台统计分析")
    @Login
    public R carForStand(@RequestParam Map<String, Object> params) {
        List<Map<String, Object>> result = taskCarTaskService.carForStand(params);
        int totalTime = 0;
        int totalSize = 0;
        int TTT = 0;
        for (Map<String, Object> map : result) {
            totalTime = totalTime + Integer.valueOf(map.get("TTT").toString());
            totalSize = totalSize + Integer.valueOf(map.get("carCount").toString());
        }
        if (totalTime > 0 && totalSize > 0) {
            TTT = totalTime / totalSize;
        }
        return R.ok().put(Constant.DATA, result).put("TTT", TTT);
    }

}
